# Maintainer: Johannes Schindelin <johannes.schindelin@gmx.de>

_realname=msmtp
pkgbase="mingw-w64-${_realname}"
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.8.11
pkgrel=1
pkgdesc="An SMTP client (mingw-w64)"
arch=('any')
license=('GPL2+')
url="https://msmtp.sourceforge.io/"
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gettext"
         "${MINGW_PACKAGE_PREFIX}-gnutls"
         "${MINGW_PACKAGE_PREFIX}-gsasl"
         "${MINGW_PACKAGE_PREFIX}-libffi"
         "${MINGW_PACKAGE_PREFIX}-libidn"
         "${MINGW_PACKAGE_PREFIX}-libwinpthread")
options=('strip')
source=(https://marlam.de/msmtp/releases/${_realname}-${pkgver}.tar.xz{,.sig}
        '0001-include-winsock2.patch')
sha256sums=('f25f0fa177ce9e0ad65c127e790a37f35fb64fee9e33d90345844c5c86780e60'
            'SKIP'
            '3729fc8d9a11370324561a76cafe09035391e48c9a55876d1aaa5077944ebf8d')
validpgpkeys=('2F61B4828BBA779AECB3F32703A2A4AB1E32FD34')

prepare () {
  cd ${srcdir}/${_realname}-${pkgver}

  patch -p1 -i "${srcdir}/0001-include-winsock2.patch"
  #autoreconf -fiv
}

build() {
  [[ -d ${srcdir}/build-${MINGW_CHOST} ]] && rm -rf ${srcdir}/build-${MINGW_CHOST}
  mkdir build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}
  ../${_realname}-${pkgver}/configure \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX}

  sed -i 's/-R\/mingw..\/lib//' src/Makefile
  touch ${srcdir}/${_realname}-${pkgver}/src/*.c
  make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR="${pkgdir}" install
  install -Dm0644 ${srcdir}/${_realname}-${pkgver}/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING
}
